﻿using Snake.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Snake
{
    class RankList
    {
        public int Barid { get; set; }
        public int Userid { get; set; }
        public int Score { get; set; }
        public int Len { get; set; }
        public int Time { get; set; }
        public string Username { get; set; }
        public string DateTime { get; set; }

        static List<IdList> IdLists = new List<IdList>();

        public RankList(int barid,int userid,int score,int len,int time)
        {
            Barid = barid;
            Userid = userid;
            Score = score;
            Len = len;
            Time = time;
            foreach(var p in IdLists)
            {
                if(p.ID==userid)
                {
                    Username = p.Username;
                    break;
                }
            }
            if (Username == null) 
            {
                Username = HttpRequest.GetUsername(userid);
                IdLists.Add(new IdList(userid, Username));
            }
        }
        public override string ToString()
        {
            string score = Score.ToString("000000")+"\t";
            string len = Len.ToString()+"\t";
            string username = Username.ToString()+"\t";
            var result = score + len + username;

            return result;
        }
    }
    class IdList
    {
        public int ID { get; set; }
        public string Username { get; set; }
        public IdList(int id,string username)
        {
            ID = id;
            Username = username;
        }
        public IdList() { }
    }
}
